<?php include "../public/header.php"?>
<?php include "../public/header_public.php"?>
<?php include "../public/header_edit.php"?>
<script src="/static/admin/js/math.js"></script>
<link rel="stylesheet" type="text/css" href="/static/admin/css/main.css">
<style>
    .left_but{padding: 10px 0 10px 15px;border-bottom: 1px solid #d1d1d1}
    .layui-card{padding-bottom: 0;margin-bottom: 0}
    .layui-table-tool-temp{padding-right:0 }
    .layui-table tr {
        height: unset !important;
        line-height: unset !important;
    }
    .layui-table-hover,.table-click-color{
        background-color: unset!important;
    }
    .layui-table tbody tr:hover{background-color: unset;}
    .qingbgclr{background-color: #666!important;color: #FFFFFF;}
    .qingbgclr:hover{background-color: #666!important;color: #FFFFFF;}
    .opTable-open-td tr:hover{background-color: #666!important;color: #FFFFFF!important;}
    div[lay-id="datalist"]>.layui-table-box>.layui-table-body{
        height: 425px!important;
    }
    .layui-form{height: unset!important;}

    .navTr1{background-color: #FFFFFF!important;}
    .navTr1:hover{background-color: #FFFFFF!important;}
    .navTr2{background-color: #d3e7ff!important;}
    .navTr2:hover{background-color: #d3e7ff!important;}
    .navTr3{background-color: #ed6969!important;}
    .navTr3:hover{background-color: #ed6969!important;}
    .navTr4{background-color: #97c5fb!important;}
    .navTr4:hover{background-color: #97c5fb!important;}

    .listTr1{background-color: #FFFFFF;}
    .listTr1:hover{background-color: #FFFFFF;}
    .listTr2{background-color: #d3e7ff;}
    .listTr2:hover{background-color: #d3e7ff;}
    .listTr3{background-color: #ed6969;}
    .listTr3:hover{background-color: #ed6969;}
    .listTr4{background-color: #97c5fb;}
    .listTr4:hover{background-color: #97c5fb;}
    .opt-btn-group button{height: 25px;line-height: 25px}
    .layui-form-select dl{position: fixed;}
    .layui-form-selectup dl {top: auto!important;bottom: 36px!important;}
    #commentForm .layui-table td, #commentForm .layui-table th{padding: 0!important;}
    .layui-input{padding-left: 5px!important;}

    .layui-table[lay-size="sm"] td, .layui-table[lay-size="sm"] th {
        padding-top: 0;
        padding-right: 0;
        padding-bottom: 0;
        padding-left: 0;
        font-size: 14px;
    }
    #queshelp{padding: 0 4px !important;position: absolute;right: 88px;top: 11px;height: 30px;line-height: 27px;}


    .td2{width: 120px!important;}
    .td3{width: 150px!important;}
    .td4{width: 200px!important;}
    .td5{}
    .td6{width: 70px!important;}
    .td7{width: 130px!important;}
    .td8{width: 80px!important;}
    .td9{width: 80px!important;}
    .td10{width: 120px!important;}
    .td11{width: 120px!important;}
    .td12{width: 150px!important;}

    #cuss tr th{font-weight: bold;}
    #cuss tr td span{margin-left: 5px}
</style>
<body class="laytp-container" onselectstart="return false">
<div style="height: 45px"></div>
<div id="opt_nav">
</div>
<div id="dialog">
    <div class="page-title" id="page-title">
        <div class="page-title-con">
            <span class="title" id="titss"></span>
            <div class="move_title"></div>
            <div class="page-title-opt-list">
                <span id="page-close" class="page-close" onclick="layer_close()">×</span>
            </div>
        </div>
    </div>
</div>
<?php include "dao.php"?>

<div class="layui-card" id="table-card">
    <div class="layui-card-body">
        <div class="layui-row">
            <div class="layui-col-md12" id="table_list">
                <div class="layui-card-body toptab">
                    <table id="datalist" lay-filter="datalist"></table>
                </div>
            </div>
            <div style="clear:both;height: 10px;background-color: #e6e6e6 !important"></div>
            <div class="layui-form layui-form-pane" id="commentForm">
                <div class="main-container" style="margin:0!important;padding: 0 10px!important;">
                    <div class="layui-form-item height_auto" style="padding: 0!important;">
                            <div class="short_table_list" key="1">
                                <div style="padding: 10px 0 5px 0;">
                                    <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_add_row">插入行</button>
                                    <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_del_row">删除行</button>
                                    <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_del_all">删除全部</button>
                                    <button type="button" onclick="check_mark(1)" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn">人工费</button>
                                    <button type="button" onclick="check_mark(2)" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn">材料费</button>
                                    <button type="button" onclick="check_mark(3)" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn">机械费</button>
                                    <button type="button" onclick="check_mark(4)" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn">分包费</button>
                                    <button type="button" onclick="chai_enfeat()" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn">拆分人材机</button>
                                    <button type="button" onclick="list_tplex()" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn">复用到...</button>
                                    <button type="button" onclick="saveinfo()" class="layui-btn layui-btn-sm btn-dark marginr5">保存</button>
                                    <button type="button" onclick="quinfo()" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn">取消</button>
                                </div>
                                <div style="overflow: auto">
                                    <div style="max-width: 2000px;overflow: hidden">
                                        <table class="layui-table" lay-size="sm" id="short_tables">
                                            <thead id="cuss" class="xustab">
                                            <tr style="height: 35px!important">
                                                <th class="td1" width="45">序号</th>
                                                <th class="td2"><span><text>*</text>费用类型</span></th>
                                                <th class="td3"><span>类别</span></th>
                                                <th class="td4"><span><text>*</text>名称</span></th>
                                                <th class="td5"><span>特征描述</span></th>
                                                <th class="td6"><span><text>*</text>单位</span></th>
                                                <th class="td7"><span>含量计算式</span></th>
                                                <th class="td8"><span>含量</span></th>
                                                <th class="td9"><span>损耗率</span></th>
                                                <th class="td10"><span><text>*</text>不含税单价(元)</span></th>
                                                <th class="td11"><span><text>*</text>成本单价(元)</span></th>
                                                <th class="td12"><span>备注</span></th>
                                            </tr>
                                            </thead>
                                            <tbody class="short_table_tbody" id="list_list" style="max-height:2000px!important;min-height: 200px;height: auto!important;"></tbody>
                                        </table>
                                    </div>
                                </div>
                                <div class="listerror">提示：<span></span></div>
                            </div>
                        </div>
                </div>
            </div>




        </div>
    </div>
</div>

<script type="text/html" id="toolbarDemo">
    <div class = "layui-btn-container">
<!--        <button class="layui-btn layui-btn-primary outbut" onclick="auth_but_func_export()">导出清单为Excel-待完成</button>-->
        <button id="queshelp" class="layui-btn layui-btn-sm layui-btn-primary" style="width: 30px"><i class="layui-icon layui-icon-help"></i></button>
        <div class="biantit" style="color: #248bfe;font-size: 13px;float: right;margin-right: 130px;position: relative;top: 11px;"></div>
    </div>
</script>

<script type="text/javascript">

    drag_column('short_tables');
    var typeArr,basetypeArr,xuanValunit;

    layui.use(["laytp",'laypage','table','dropdown','form','soulTable'], function () {
        var laypage = layui.laypage, table = layui.table, dropdown = layui.dropdown, form = layui.form, soulTable = layui.soulTable;



        layui.config({
            base: '../../static/component/lib/opTable'
        }).extend({
            opTable: '/opTable'
        }).use(['opTable'],function() {
            layui.opTable.render({
                elem: '#datalist'
                ,toolbar: TabInit.toolbar
                ,method:TabInit.method
                ,defaultToolbar: ['filter', '', 'print']
                ,height: 'full-102'
                ,url: server_api_name+ask_main_basalnav_list
                ,page: false
                ,openType: 1
                ,request: {pageName: 'page',limitName: 'pagesize'}
                ,where:{enginid:param_enginid}
                ,parseData: function(res){
                    $(".biantit").html(res.data.tit);
                    typeArr = res.data.type;
                    basetypeArr = res.data.basetypearr;




                    var listAddStr = '';
                    listAddStr += '<tr>';
                    listAddStr += '<td class="td1" style="width: 45px">1</td>';
                    listAddStr += '<td class="td2"><select class="layui-select type" lay-filter="type">';
                    listAddStr += '<option value="">请选择</option>';
                    for(var j in typeArr){
                        listAddStr += '<option value="'+j+'">'+typeArr[j]+'</option>';
                    }
                    listAddStr += '</select></td>';
                    listAddStr += '<td class="td3"><select class="layui-select basetype">';
                    listAddStr += '<option value="">请选择</option>';
                    listAddStr += '</select></td>';
                    listAddStr += '<td class="td4"><input type="text" class="layui-input name"></td>';
                    listAddStr += '<td class="td5"><textarea class="layui-textarea curarea guige"></textarea></td>';
                    listAddStr += '<td class="td6"><input type="text" class="layui-input valunit"></td>';
                    listAddStr += '<td class="td7"><input type="text" class="layui-input content_exp" value="1"></td>';
                    listAddStr += '<td class="td8"><input type="number" class="layui-input content" value="1" readonly></td>';
                    listAddStr += '<td class="td9"><input type="number" class="layui-input loss_rate" value="0"></td>';
                    listAddStr += '<td class="td10"><input type="number" class="layui-input no_price">';
                    listAddStr += '<td class="td11"><input type="number" class="layui-input price"></td>';
                    listAddStr += '<td class="td12"><input type="text" class="layui-input explain"></td>';
                    listAddStr += '</tr>';
                    short_table_opt_func(listAddStr,1);

                    return {
                        "code": res.code,
                        "msg": res.message,
                        "count": res.data.total,
                        "data": res.data.data
                    };
                }
                ,response: {statusCode: 2000}
                ,cols: [[
                    {field:'encode',title:'项目编码',width:140}
                    ,{field:'enname',title:'项目名称',templet: function(d){return '<span class="enname" val="'+d.enname+'">'+d.enname+'</span>';},width:300}
                    ,{field:'enfeat',title:'项目特征描述',width:400}
                    ,{field:'enunit',title:'计量单位',width:100}
                    ,{field:'enword',title:'工程量',width:150}
                    ,{field:'renprice',title:'人工费(元)',width:150}
                    ,{field:'caiprice',title:'材料费(元)',width:150}
                    ,{field:'jiprice',title:'机械费(元)',width:150}
                    ,{field:'fenprice',title:'专业分包(元)',width:150}
                    ,{field:'price',title:'综合成本单价(元)',width:150}
                    ,{field:'money',title:'综合成本合计(元)',width:150}
                    ,{field:'renfee',title:'人工费合计(元)',width:150}
                    ,{field:'caifee',title:'材料费合计(元)',width:150}
                    ,{field:'jifee',title:'机械费合计(元)',width:150}
                    ,{field:'fenfee',title:'专业分包合计(元)',width:150}
                ]]
                ,done: function(res, curr, count){
                    $('div[lay-id="datalist"] .layui-table-header thead>tr>th:first-child').find('.layui-table-sort').remove();
                    res.data.forEach(function (item, index) {
                        $("div[lay-id='datalist']").find('tr').eq(index + 1).addClass('navTr'+item['iszhu']);
                    });
                    curMoveTables('layuitablebody', 'dragIcon')


                    var curTipIndex = '';
                    $("#queshelp").on("mouseenter", function () {
                        var content = '<div style="padding: 5px; font-size: 16px; color: #FFFFFF;">' +
                            '<div>白色：未组价</div>'+
                            '<div>浅蓝色：已全部组价</div>'+
                            '<div>红色：部分组价</div>'+
                            '<div>深蓝色：已组价但包含成本价为0的项</div>'+
                            "</div>";
                        curTipIndex = layer.tips(content,this, {time: -1, maxWidth: 280, tips: [3, "#2272eb"],});
                    }).on("mouseleave", function () {
                        layer.close(curTipIndex);
                    });
                }
                ,openTable: function (itemData) {
                    return {
                        elem: '#child_1_' + itemData.LAY_INDEX
                        ,id: 'child_1_' + itemData.LAY_INDEX
                        ,method:'post'
                        ,url: server_api_name+ask_main_basallist_list
                        ,page: false
                        ,where:{enginid:param_enginid,fenname:itemData.enname}
                        ,parseData: function(res){
                            return {
                                "code": res.code,
                                "msg": res.message,
                                "count": res.data.total,
                                "data": res.data.data
                            };
                        }
                        ,response: {statusCode: 2000}
                        ,cols: [[
                            {field:'encode',title:'项目编码',width:140}
                            ,{field:'enname',title:'项目名称',templet: function(d){return '<span class="listid listid'+d.id+'" id="'+d.id+'" fenname="'+d.fenname+'">'+d.enname+'</span>';},width:300}
                            ,{field:'enfeat',title:'项目特征描述',width:400}
                            ,{field:'enunit',title:'计量单位',width:100}
                            ,{field:'enword',title:'工程量',width:150}
                            ,{field:'renprice',title:'人工费(元)',width:150}
                            ,{field:'caiprice',title:'材料费(元)',width:150}
                            ,{field:'jiprice',title:'机械费(元)',width:150}
                            ,{field:'fenprice',title:'专业分包(元)',width:150}
                            ,{field:'price',title:'综合成本单价(元)',width:150}
                            ,{field:'money',title:'综合成本合计(元)',width:150}
                            ,{field:'renfee',title:'人工费合计(元)',width:150}
                            ,{field:'caifee',title:'材料费合计(元)',width:150}
                            ,{field:'jifee',title:'机械费合计(元)',width:150}
                            ,{field:'fenfee',title:'专业分包合计(元)',width:150}
                        ]]
                        ,done: function(res, curr, count){
                            res.data.forEach(function (item, index) {
                                $("div[lay-id='child_1_"+itemData.LAY_INDEX+"']").find('tr').eq(index + 1).addClass('listTr'+item['exists']);
                            });

                            $(".opTable-open-td").find('th').hide();
                        }
                    }
                }
            });
        });

        form.on('select(type)', function(data){
            var this_basetype = basetypeArr[data.value];

            var str = '<option value="">请选择</option>';
            for(var i=0;i<this_basetype.length;i++){
                str += '<option value="'+this_basetype[i].name+'">'+this_basetype[i].name+'<option>';
            }
            data.othis.parent().parent().find('.basetype').html(str);
            render_from();
        });


        function listTableSearch(form, table){
            $("#TableSearchButton").on('click', function(){
                searchTableFunc(form, table)
            });
        }
        listTableSearch(form, table);
    });


    // 点击基底清单出现明细
    var oldBotId = 0;
    $('body').on('click','.opTable-open-td tr',function () {
        saveinfo(this);
    });

    function quinfo() {
        open_basal_list();
    }

    function saveinfo(xuanObj=null, callback=null) {
        if(parseInt(oldBotId) < 1){
            open_basal_list(xuanObj);
        }else{
            var list = [''],repeat = [];
            try {
                $('#list_list tr').each(function (i) {
                    var type = $(this).find('.type').val();
                    var basetype = $(this).find('.basetype').val();
                    var markid = $(this).find('.name').attr('markid') || 0;
                    var name = $(this).find('.name').val();
                    var guige = $(this).find('.guige').val();
                    var valunit = $(this).find('.valunit').val();
                    var content_exp = $(this).find('.content_exp').val();
                    var content = $(this).find('.content').val();
                    var loss_rate = $(this).find('.loss_rate').val();
                    var no_price = $(this).find('.no_price').val();
                    var price = $(this).find('.price').val();
                    var explain = $(this).find('.explain').val();

                    var index = i + 1;
                    if(!type){
                        throw new Error('第'+index+'行，请选择费用类型');
                    }
                    if(!name){
                        throw new Error('第'+index+'行，请填写名称');
                    }
                    if(!valunit){
                        throw new Error('第'+index+'行，请填写单位');
                    }
                    if(!no_price){
                        throw new Error('第'+index+'行，请填写不含税单价');
                    }
                    if(!price){
                        throw new Error('第'+index+'行，请填写成本单价');
                    }

                    // 费用类型	类别	*名称	特征描述	*单位
                    var str = type+'-'+basetype+'-'+name+'-'+guige+'-'+valunit;
                    if($.inArray(str, repeat) != -1){
                        throw new Error('第'+index+'行，内容重复');
                    }
                    repeat.push(str);

                    list.push({
                        type:type,
                        basetype:basetype,
                        markid:markid,
                        name:name,
                        guige:guige,
                        valunit:valunit,
                        content_exp:content_exp,
                        content:content,
                        loss_rate:loss_rate,
                        no_price:no_price,
                        price:price,
                        explain:explain,
                        enginid: param_enginid,
                        basalid: oldBotId
                    });
                });
            } catch(e) {
                $(".listerror").find('span').text(e.message);
                $(".listerror").show();
                return false;
            }
            $(".listerror").hide();

            facade.ajax({url: ask_main_basallist_add, data:{basalid:oldBotId,list:list,enginid: param_enginid}}).done(function(res){
                if (res.code === 2000) {
                    facade.success("提交成功!");
                    var updGengBasal = res.data.updGengBasal;
                    var updGengBasalParent = res.data.updGengBasalParent;

                    for (var mmm in updGengBasal){
                        var ClsnameObj = $('.toptab .listid'+updGengBasal[mmm].id);
                        if(ClsnameObj.length > 0){
                            var gaiObj = ClsnameObj.parent('div').parent('td').parent('tr');
                            gaiObj.find('td[data-field="renprice"] div').text(updGengBasal[mmm].renprice);
                            gaiObj.find('td[data-field="caiprice"] div').text(updGengBasal[mmm].caiprice);
                            gaiObj.find('td[data-field="jiprice"] div').text(updGengBasal[mmm].jiprice);
                            gaiObj.find('td[data-field="fenprice"] div').text(updGengBasal[mmm].fenprice);
                            gaiObj.find('td[data-field="price"] div').text(updGengBasal[mmm].price);
                            gaiObj.find('td[data-field="money"] div').text(updGengBasal[mmm].money);
                            gaiObj.find('td[data-field="renfee"] div').text(updGengBasal[mmm].renfee);
                            gaiObj.find('td[data-field="caifee"] div').text(updGengBasal[mmm].caifee);
                            gaiObj.find('td[data-field="jifee"] div').text(updGengBasal[mmm].jifee);
                            gaiObj.find('td[data-field="fenfee"] div').text(updGengBasal[mmm].fenfee);
                        }
                    }

                    for (var nnn in updGengBasalParent){
                        var ParnameObj = $('.toptab .enname[val="'+updGengBasalParent[nnn].enname+'"]');
                        if(ParnameObj.length > 0){
                            var ParObj = ParnameObj.parent('div').parent('td').parent('tr');
                            ParObj.find('td[data-field="renprice"] div').text(updGengBasalParent[nnn].renprice);
                            ParObj.find('td[data-field="caiprice"] div').text(updGengBasalParent[nnn].caiprice);
                            ParObj.find('td[data-field="jiprice"] div').text(updGengBasalParent[nnn].jiprice);
                            ParObj.find('td[data-field="fenprice"] div').text(updGengBasalParent[nnn].fenprice);
                            ParObj.find('td[data-field="price"] div').text(updGengBasalParent[nnn].price);
                            ParObj.find('td[data-field="money"] div').text(updGengBasalParent[nnn].money);
                            ParObj.find('td[data-field="renfee"] div').text(updGengBasalParent[nnn].renfee);
                            ParObj.find('td[data-field="caifee"] div').text(updGengBasalParent[nnn].caifee);
                            ParObj.find('td[data-field="jifee"] div').text(updGengBasalParent[nnn].jifee);
                            ParObj.find('td[data-field="fenfee"] div').text(updGengBasalParent[nnn].fenfee);
                        }
                    }

                    open_basal_list(xuanObj, callback);
                }
            });


        }
    }
    function open_basal_list(xuanObj=null, callback=null) {
        if(xuanObj){
            $('.opTable-open-td tr').removeClass('qingbgclr');
            $(xuanObj).addClass('qingbgclr');
            oldBotId = $(xuanObj).find('.listid').attr('id') || 0;
        }
        if(parseInt(oldBotId) > 0){
            facade.ajax({type: 'get', url: ask_main_basallist_add,data:{id:oldBotId}}).done(function(res){
                if (res.code === 2000) {
                    xuanValunit = res.data.data.enunit
                    $(".biantit").html(res.data.tit);

                    var editStr = '';
                    var list = res.data.list;
                    for (var i=0;i<list.length;i++){
                        editStr += '<tr>';
                        editStr += '<td class="td1" style="width: 45px">'+(i + 1)+'</td>';
                        editStr += '<td class="td2"><select class="layui-select type" lay-filter="type">';
                        editStr += '<option value="">请选择</option>';
                        for(var j in typeArr){
                            if(list[i].type == j){
                                editStr += '<option value="'+j+'" selected>'+typeArr[j]+'</option>';
                            }else{
                                editStr += '<option value="'+j+'">'+typeArr[j]+'</option>';
                            }
                        }
                        editStr += '</select></td>';
                        editStr += '<td class="td3"><select class="layui-select basetype">';
                        editStr += '<option value="">请选择</option>';

                        var this_basetype = basetypeArr[list[i].type];
                        for(var j=0;j<this_basetype.length;j++){
                            if(list[i].basetype == this_basetype[j].name){
                                editStr += '<option value="'+this_basetype[j].name+'" selected>'+this_basetype[j].name+'</option>';
                            }else{
                                editStr += '<option value="'+this_basetype[j].name+'">'+this_basetype[j].name+'</option>';
                            }
                        }
                        editStr += '</select></td>';
                        editStr += '<td class="td4"><input type="text" class="layui-input name" markid="'+list[i].markid+'" value="'+list[i].name+'"></td>';
                        editStr += '<td class="td5"><textarea class="layui-textarea curarea guige">'+list[i].guige+'</textarea></td>';
                        editStr += '<td class="td6"><input type="text" class="layui-input valunit" value="'+list[i].valunit+'"></td>';
                        editStr += '<td class="td7"><input type="text" class="layui-input content_exp" value="'+list[i].content_exp+'"></td>';
                        editStr += '<td class="td8"><input type="number" class="layui-input content" readonly value="'+list[i].content+'"></td>';
                        editStr += '<td class="td9"><input type="number" class="layui-input loss_rate" value="'+list[i].loss_rate+'"></td>';
                        editStr += '<td class="td10"><input type="number" class="layui-input no_price" value="'+list[i].no_price+'">';
                        editStr += '<td class="td11"><input type="number" class="layui-input price" value="'+list[i].price+'"></td>';
                        editStr += '<td class="td12"><input type="text" class="layui-input explain" value="'+list[i].explain+'"></td>';
                        editStr += '</tr>';
                    }
                    $('#list_list').html(editStr);
                    update_refresh_row_func();


                    render_from();

                    if(callback){
                        callback();
                    }
                }
            });
        }
        return;
    }
    function check_mark(type) {
        if(parseInt(oldBotId) < 1){
            facade.error("请选择要操作的清单"); return false
        }
        var fenname = $('.toptab .listid'+oldBotId).attr('fenname') || '';

        layer.closeAll();
        openPageRight('check_mark.php?page=basal&enginid='+param_enginid+'&type='+type+'&fenname='+encodeURI(fenname), '70%', '78%', 0);
    }
    function chai_enfeat() {
        if(parseInt(oldBotId) < 1){
            facade.error("请选择要操作的清单"); return false
        }
        var ClsnameObj = $('.toptab .listid'+oldBotId);
        if(ClsnameObj.length < 1){
            return false;
        }
        var gaiObj = ClsnameObj.parent('div').parent('td').parent('tr');
        var enname = gaiObj.find('td[data-field="enname"] div').text();
        var enfeat = gaiObj.find('td[data-field="enfeat"] div').html();
        var enunit = gaiObj.find('td[data-field="enunit"] div').text();
        var arr = enfeat.split('<br>');

        var length = $('#list_list tr').length+1
        $.each(arr, function (k,v) {
            if(v == ''){return true}
            var str_ = '';
            str_ += '<tr>';
            str_ += '<td class="td1" style="width: 45px">'+length+'</td>';
            str_ += '<td class="td2"><select class="layui-select type" lay-filter="type">';
            str_ += '<option value="">请选择</option>';
            for(var j in typeArr){
                str_ += '<option value="'+j+'">'+typeArr[j]+'</option>';
            }
            str_ += '</select></td>';
            str_ += '<td class="td3"><select class="layui-select basetype">';
            str_ += '<option value="">请选择</option>';
            str_ += '</select></td>';
            str_ += '<td class="td4"><input type="text" class="layui-input name" markid="0" value="'+enname+'"></td>';
            str_ += '<td class="td5"><textarea class="layui-textarea curarea guige">'+v+'</textarea></td>';
            str_ += '<td class="td6"><input type="text" class="layui-input valunit" value="'+enunit+'"></td>';
            str_ += '<td class="td7"><input type="text" class="layui-input content_exp" value="1"></td>';
            str_ += '<td class="td8"><input type="number" class="layui-input content" readonly value="1"></td>';
            str_ += '<td class="td9"><input type="number" class="layui-input loss_rate" value="0"></td>';
            str_ += '<td class="td10"><input type="number" class="layui-input no_price" value="0"></td>';
            str_ += '<td class="td11"><input type="number" class="layui-input price" value="0"></td>';
            str_ += '<td class="td12"><input type="text" class="layui-input explain"></td>';
            str_ += '</tr>';
            length++;
            $('#list_list').append(str_);
        });
        update_refresh_row_func();
        render_date();
        render_from();
    }
    function list_tplex() {
        if(parseInt(oldBotId) < 1){
            facade.error("请选择要操作的清单"); return false
        }
        saveinfo(null, function () {
            openPageRight('basal_tplex.php?id='+oldBotId, '60%', '100%');
        })
    }







    $('#list_list').on('input propertychange','.content_exp,.loss_rate,.no_price',function () {
        ji_suan_list();
    });
    function ji_suan_list(){
        $('#list_list tr').each(function () {
            var content_exp = $(this).find('.content_exp').val() || 0;
            var content = mathStrNumber(content_exp, 6);
            $(this).find('.content').val(content);

            var loss_rate = parseFloat($(this).find('.loss_rate').val()) || 0;
            var no_price = parseFloat($(this).find('.no_price').val()) || 0;

            var price = mathRound (no_price * (1 + loss_rate) * content, 3);
            $(this).find('.price').val(price);
        });
    }





    function short_table_opt_func(bridge_str, table_key, xmObj={}){
        if(!table_key || table_key == undefined || table_key == 'undefined'){
            table_key = 1;
        }
        update_refresh_row_func();

        $(".short_table_add_row").click(function () {
            if($(this).parents('.short_table_list').attr('key') != table_key){
                return false;
            }

            var sle = false;
            var sle_obj;
            $.each($(this).parents('.short_table_list').find('table').children('tbody').children('tr'),function () {
                if($(this).attr('sle') == 'sle'){
                    sle = true;
                    sle_obj = $(this);
                }
            });

            if(!sle){
                $(this).parents('.short_table_list').find('table').children('tbody').append(bridge_str);
                $(this).parents('.short_table_list').find('table').children('tbody').find('tr:nth-last-child(1)').find('.valunit').val(xuanValunit)
            }else{
                var chaNum = parseInt($(sle_obj).index())+2;
                $(sle_obj).after(bridge_str);
                $(this).parents('.short_table_list').find('table').children('tbody').find('tr:nth-child('+chaNum+')').find('.valunit').val(xuanValunit)
            }

            $.each($(this).parents('.short_table_list').find('table').children('tbody').children('tr'),function (key,val) {
                $(this).children('td:first-child').html(key+1);
            });

            // 设置滚动条
            if($(this).parents('.short_table_list').find('table').children('tbody').height() >= 500){
                $(this).parents('.short_table_list').find('table').children('thead').css('overflow-y','scroll')
            }

            render_date();
            render_from();
            update_refresh_row_func();
            set_list_render_xmselect(xmObj);
            reload_table_list_bac('short_table_list');
        });

        $(".short_table_copy_row").click(function () {
            if($(this).parents('.short_table_list').attr('key') != table_key){
                return false;
            }
            var sle = false;
            var sle_obj,sle_html;
            $.each($(this).parents('.short_table_list').find('table').children('tbody').children('tr'),function () {
                if($(this).attr('sle') == 'sle'){
                    sle = true;
                    sle_obj = $(this);
                    sle_html = '<tr>'+$(this).formhtml()+'</tr>';

                    if($(this).find('.filedetaobjdata').html() != undefined){
                        var filedetaobjdataStr = $(this).find('.filedetaobjdata').html();
                        var filedetaobjdataLength = $(this).find('.filedetaobjdata').parent('div').find('span:first-child').html();
                        if(filedetaobjdataLength > 0){
                            $(this).find('.filedetaobjdata').parent('div').find('span:first-child').html(0);
                        }
                        $(this).find('.filedetaobjdata').html('[]');
                        sle_html = '<tr>'+$(this).formhtml()+'</tr>';
                        if(filedetaobjdataLength > 0){
                            $(this).find('.filedetaobjdata').parent('div').find('span:first-child').html(filedetaobjdataLength);
                        }
                        $(this).find('.filedetaobjdata').html(filedetaobjdataStr);
                    }
                }
            });

            if(!sle){
                layer.msg("请选中要复制的行");return false;
            }else{
                $(sle_obj).after(sle_html);
            }
            $.each($(this).parents('.short_table_list').find('table').children('tbody').children('tr'),function (key,val) {
                $(this).children('td:first-child').html(key+1);
            });

            // 设置滚动条
            if($(this).parents('.short_table_list').find('tbody').height() >= 500){
                $(this).parents('.short_table_list').find('thead').css('overflow-y','scroll')
            }

            render_date();
            render_from();
            update_refresh_row_func();
            set_list_render_xmselect(xmObj);
            reload_table_list_bac('short_table_list');
        });

        $(".short_table_del_row").click(function () {
            if($(this).parents('.short_table_list').attr('key') != table_key){
                return false;
            }
            var sle = false;
            var sle_obj;
            $.each($(this).parents('.short_table_list').find('table').children('tbody').children('tr'),function () {
                // 样式处理
                $(this).find('td').css({'border': '1px solid #eee'});
                $('.layui-table thead th ').css({'border-bottom-color': '#eee'});

                if($(this).attr('sle') == 'sle'){
                    sle = true;
                    sle_obj = $(this);
                }
            });

            if(!sle){
                layer.msg("请选中要删除的行");return false;
            }else{
                $(sle_obj).remove();
            }

            // if($(this).parents('.short_table_list').find('table').children('tbody').children('tr').length < 1){
            //     $(this).parents('.short_table_list').children('table').children('tbody').append(bridge_str);
            // }

            $.each($(this).parents('.short_table_list').find('table').children('tbody').children('tr'),function (key,val) {
                $(this).children('td:first-child').html(key+1);
            });

            // 取消滚动条
            if($(this).parents('.short_table_list').find('tbody').height() < 500){
                $(this).parents('.short_table_list').find('thead').css('overflow-y','hidden')
            }

            render_date();
            render_from();
            update_refresh_row_func();
            set_list_render_xmselect(xmObj);
            reload_table_list_bac('short_table_list');
        });

        $(".short_table_del_all").click(function () {
            if($(this).parents('.short_table_list').attr('key') != table_key){
                return false;
            }
            var sle = false;
            var sle_obj;
            $(this).parents('.short_table_list').find('table').children('tbody').html('');

            // $(this).parents('.short_table_list').find('table').children('tbody').append(bridge_str);
            $.each($(this).parents('.short_table_list').find('table').children('tbody').children('tr'),function (key,val) {
                $(this).children('td:first-child').html(key+1);
            });

            // 取消滚动条
            if($(this).parents('.short_table_list').find('tbody').height() < 500){
                $(this).parents('.short_table_list').find('thead').css('overflow-y','hidden')
            }

            render_date();
            render_from();
            update_refresh_row_func();
            set_list_render_xmselect(xmObj);
            reload_table_list_bac('short_table_list');
        });
    }






    function update_refresh_row_func() {
        render_date();
        setTimeout(function () {
            $(".short_table_list table tbody tr").click(function () {
                $(".short_table_list table tbody tr").removeClass('line-row');
                $(".short_table_list table tbody tr").attr('sle','');
                $(this).addClass('line-row');
                $(this).attr('sle','sle');
            });

            var divs = document.querySelectorAll(".curarea");
            for (let i = 0; i < divs.length; ++i) {
                var deaHeight = divs[i].scrollHeight
                deaHeight = deaHeight < 35 ? 35 : deaHeight
                if(deaHeight == 35){
                    $(divs[i]).attr('style','height:'+deaHeight+'px!important;line-height:35px!important')
                }else{
                    $(divs[i]).attr('style','height:'+deaHeight+'px!important')
                }

                divs[i].addEventListener('input', (e) => {
                    var shiHei = parseInt(e.target.scrollHeight);
                    shiHei = shiHei < 35 ? 35 : shiHei
                    if(shiHei == 35){
                        $(divs[i]).attr('style','height:'+shiHei+'px!important;line-height:35px!important')
                    }else{
                        $(divs[i]).attr('style','height:'+shiHei+'px!important')
                    }
                });
            }


            setTimeout(function () {
                $(".xustab").attr('style','overflow-y: hidden;');
            },100);
        },1000);
    }
</script>
</body>
</html>
